package com.ty.day7;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : txy
 * @create : 2023/11/30 16:35
 */
public class SynchronizedDemo01 {
    public static void main(String[] args) {
        System.out.println(new Date());
        Thread t1 = new Thread(() -> {
            SynchronizedDemo01.girl("冲击波");
            System.out.println(new Date());
        });
        Thread t2 = new Thread(() -> {
            SynchronizedDemo01.girl("车波");
            System.out.println(new Date());
        });
        t1.start();
        t2.start();
    }

    public static void girl(String name) {
        try {
            System.out.println(name + "来了，二楼贵宾一位");
            synchronized (SynchronizedDemo01.class) {
                Thread.sleep(3000);
                System.out.println(name + "的服务结束");
            }
            Thread.sleep(3000);
            System.out.println(name + "走了");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

